package com.smart.gui;

import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;

public class SMART_T_Questionnaire_Form extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private String SMART_T_ANALYSIS_ANSWER = "Recommendation: ";
	private JLabel txtAnswer = new JLabel();

	/**
	 * singleton pattern -- getInstance
	 */
	private static SMART_T_Questionnaire_Form uniqueInstanceForm;

	public static synchronized SMART_T_Questionnaire_Form getInstance() {
		if (uniqueInstanceForm == null) {
			try {
				uniqueInstanceForm = new SMART_T_Questionnaire_Form();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return uniqueInstanceForm;
	}

	/**
	 * Create the frame.
	 */
	public SMART_T_Questionnaire_Form() {
		setBackground(Color.WHITE);

		setTitle("SMART-T Recommendation Window");
		setResizable(false);
		setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
		setBounds(25, 25, 550, 100);
		contentPane = new JPanel();
		contentPane.setBackground(Color.WHITE);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		contentPane
				.setLayout(new FormLayout(new ColumnSpec[] {
						FormFactory.UNRELATED_GAP_COLSPEC,
						ColumnSpec.decode("default:grow"), }, new RowSpec[] {
						FormFactory.PARAGRAPH_GAP_ROWSPEC,
						RowSpec.decode("20px"),
						FormFactory.RELATED_GAP_ROWSPEC,
						RowSpec.decode("20px"),
						FormFactory.RELATED_GAP_ROWSPEC,
						RowSpec.decode("20px"),
						FormFactory.RELATED_GAP_ROWSPEC,
						RowSpec.decode("20px"),
						FormFactory.RELATED_GAP_ROWSPEC,
						FormFactory.DEFAULT_ROWSPEC, }));

		txtAnswer.setText(SMART_T_ANALYSIS_ANSWER);
		contentPane.add(txtAnswer, "2, 2, fill, top");

	}

	public void showAnswer(String answer) {
		txtAnswer.setText(SMART_T_ANALYSIS_ANSWER + answer);
		uniqueInstanceForm.setVisible(true);
	}
}
